package per.srp.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import per.srp.demo.carLink.CarManagerServer;
import per.srp.demo.carLink.Utils.MyThread;

@SpringBootApplication
public class DemoApplication {
    private static ConfigurableApplicationContext springbootCAC = null;
    public static void main(String[] args) {
        //启动小车服务系统
        startCarServer();
        springbootCAC = SpringApplication.run(DemoApplication.class, args);
    }

    private static void startCarServer(){
        MyThread t = new MyThread() {
            @Override
            public void run() {
                try {
                    CarManagerServer.run();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
    }

    public static boolean exitBoot(){
        if(springbootCAC!=null){
            MyThread t = new MyThread() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(3000);
                        springbootCAC.close();
                        CarManagerServer.exit();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            return true;
        }

        return false;
    }

}
